package m.jclecai.com.adapter.holder;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.LayoutRes;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.ybq.android.spinkit.SpinKitView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.activity.NewWebViewHelperActivity;
import m.jclecai.com.animal.ExpandAnimation;
import m.jclecai.com.bean.ZqItem;
import m.jclecai.com.dialog.JczqHHDialog;
import m.jclecai.com.listener.Callback;
import m.jclecai.com.listener.OnSclestListener;
import m.jclecai.com.utils.ScreenUtil;
import m.jclecai.com.utils.Utils;
import m.jclecai.com.utils.http.FastOk;

/**
 * Created by ZD on 2017/5/4.
 */

public class JczqChildHolder extends ViewHolder implements View.OnClickListener {
    @BindView(R.id.tv_failed)
    TextView tvFailed;
    @BindView(R.id.skv)
    SpinKitView skv;
    @BindView(R.id.tv_history_one)
    TextView tvHistoryOne;
    @BindView(R.id.tv_recent_one)
    TextView tvRecentOne;
    @BindView(R.id.tv_recent_two)
    TextView tvRecentTwo;
    @BindView(R.id.tv_rank_one)
    TextView tvRankOne;
    @BindView(R.id.tv_rank_two)
    TextView tvRankTwo;
    @BindView(R.id.tv_ratio_one)
    TextView tvRatioOne;
    @BindView(R.id.tv_ratio_two)
    TextView tvRatioTwo;
    @BindView(R.id.tv_ratio_three)
    TextView tvRatioThree;
    @BindView(R.id.tv_xx)
    TextView tvXx;
    @BindView(R.id.llDetail)
    LinearLayout llDetail;
    @BindView(R.id.ll_ratio)
    LinearLayout ll_ratio;


    @BindView(R.id.item_name)
    public TextView itemName;
    @BindView(R.id.item_time)
    public TextView itemTime;
    @BindView(R.id.home_team_name)
    public TextView homeTeamName;
    @BindView(R.id.away_team_name)
    public TextView awayTeamName;
    @BindView(R.id.ll_match_title)
    public LinearLayout llMatchTitle;
    @BindView(R.id.llrqspf)
    public LinearLayout llrqspf;

    @BindView(R.id.ll_rspf_odds)
    public LinearLayout llRspfOdds;     //让胜平负的赔率的LinearLayout；
    @BindView(R.id.tv_rspf_no_sale)
    public TextView tvRspfOdds;         //显示未开售；

    @BindView(R.id.ll_spf_odds)
    public LinearLayout llSpfOdds;     //让胜平负的赔率的LinearLayout；
    @BindView(R.id.tv_spf_no_sale)
    public TextView tvSpfOdds;         //显示未开售；

    @BindView(R.id.cb_touzhu)
    public CheckBox cbTouzhu;
    @BindView(R.id.cb_more)
    CheckBox cb_more;
    @BindView(R.id.ll_all)
    public LinearLayout llAll;
    @BindView(R.id.llspf)
    public LinearLayout llspf;
    @BindView(R.id.tv_spf_txt)
    public TextView tv_spf_txt;
    @BindView(R.id.tv_rqspf_txt)
    public TextView tv_rqspf_txt;
    @BindView(R.id.llLeft)
    public LinearLayout llLeft;
    @BindView(R.id.iv_detail)
    ImageView iv_detail;

    //记录点击的数据
    Map<String, Map<String, String>> cMap;

    ZqItem mItem;
    int pager = 0;
    int mPosition = 0;
    Callback changed;
    String[] cbf, spf, bqc;
    String[] codes;
    //checkbox高度
    int cH = 0;

    public JczqChildHolder(Context context, @LayoutRes int resource) {
        super(context, resource);
        cH = ScreenUtil.dip2px(context, 40);
    }

    private void init() {
        init(this.mItem, pager, mPosition);
    }

    public void init(ZqItem item, int pager, int position) {

        cbf = getContext().getResources().getStringArray(
                R.array.jczq_cbf);
        spf = getContext().getResources().getStringArray(
                R.array.jczq_spf);
        bqc = getContext().getResources().getStringArray(
                R.array.jczq_bqc);
        this.mPosition = position;
        this.pager = pager;
        this.mItem = item;
        codes = mItem.getCodes();
        List<String[]> list = FastOk.getList(codes[16], String[].class);
        //左边队名-公共属性
        homeTeamName.setText(codes[3]);
//        homeTeamName.setTextColor(Color.parseColor(codes[17]));
        //右边队名-公共属性
        awayTeamName.setText(codes[4]);
//        awayTeamName.setTextColor(Color.parseColor(codes[17]));
        //联赛名称-公共属性
        itemName.setText(codes[2]);
        //开赛时间-公共属性
        itemTime.setText(codes[7].substring(11, 16) + "截止\n" + codes[1]);
        //隐藏所有的布局
        llspf.setVisibility(GONE);
        llrqspf.setVisibility(GONE);
        llAll.setVisibility(GONE);
        cbTouzhu.setVisibility(GONE);
        cb_more.setVisibility(GONE);
        llDetail.setAnimation(null);
        llDetail.setVisibility(mItem.isShowDetail() ? VISIBLE : GONE);

        ll_ratio.setVisibility(INVISIBLE);
        skv.setVisibility(INVISIBLE);
        tvFailed.setVisibility(INVISIBLE);
        showRatio(mItem.getRatio());

        iv_detail.setImageResource(mItem.isShowDetail() ? R.drawable.d0 : R.drawable.cz);
        tv_spf_txt.setVisibility(INVISIBLE);
        tv_rqspf_txt.setVisibility(INVISIBLE);
        resetCheckBoxStatus(cbTouzhu, "立即投注");
        resetCheckBoxStatus(cb_more, "更多玩法");
        //由于数据格式层级深入 无法预知哪个模块参数无 所以做个catch
        try {
            if (pager == 0) {//胜平负
                llspf.setVisibility(VISIBLE);
                initSPF(list);
            } else if (pager == 1) {//胜平负让
                tv_rqspf_txt.setVisibility(VISIBLE);
                llrqspf.setVisibility(VISIBLE);
                initRQSPF(list, codes[5]);
            } else if (pager == 2) {//混投
                cb_more.setVisibility(VISIBLE);
                tv_spf_txt.setVisibility(VISIBLE);
                tv_spf_txt.setText("0");
                tv_rqspf_txt.setVisibility(VISIBLE);
                llspf.setVisibility(VISIBLE);
                initSPF(list);
                llrqspf.setVisibility(VISIBLE);
                initRQSPF(list, codes[5]);
            } else if (pager == 3) {//半全场
                cbTouzhu.setVisibility(VISIBLE);
                initBQC();
            } else if (pager == 4) {//比分
                cbTouzhu.setVisibility(VISIBLE);
                initBF();
            } else if (pager == 5) {//总进球
                llAll.setVisibility(VISIBLE);
                initZJQ(list);
            } else if (pager == 6) {//单关
                cb_more.setVisibility(VISIBLE);
                tv_spf_txt.setVisibility(VISIBLE);
                tv_spf_txt.setText("0");
                tv_rqspf_txt.setVisibility(VISIBLE);
                llspf.setVisibility(VISIBLE);
                initSPF(list);
                llrqspf.setVisibility(VISIBLE);
                initRQSPF(list, codes[5]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @OnClick(R.id.llLeft)
    void showDetail() {
        iv_detail.setImageResource(!mItem.isShowDetail() ? R.drawable.d0 : R.drawable.cz);
        llDetail.startAnimation(new ExpandAnimation(llDetail, 300, !mItem.isShowDetail()));
        mItem.setShowDetail(!mItem.isShowDetail());
        if (mItem.getRatio() == null) {
            tvFailed.setVisibility(INVISIBLE);
            ll_ratio.setVisibility(INVISIBLE);
            skv.setVisibility(VISIBLE);
            if (this.changed != null)
                this.changed.callback(codes[0], new Callback() {
                    @Override
                    public void callback(JSONObject o) {
                        showRatio(o);
                        mItem.setRatio(o);
                    }

                    @Override
                    public void callbackField() {
                        super.callbackField();
                        tvFailed.setVisibility(VISIBLE);
                        ll_ratio.setVisibility(INVISIBLE);
                        skv.setVisibility(INVISIBLE);
                        //加载失败
                    }
                });
        } else {
            showRatio(mItem.getRatio());
        }
    }

    //显示赛事详情
    void showRatio(final JSONObject o) {
        if (o == null) {
            tvFailed.setVisibility(INVISIBLE);
            skv.setVisibility(VISIBLE);
            ll_ratio.setVisibility(INVISIBLE);
            return;
        }

        tvFailed.setVisibility(INVISIBLE);
        skv.setVisibility(INVISIBLE);
        //加载数据
        ll_ratio.setVisibility(VISIBLE);
        //历史交锋
        JSONArray history = o.getJSONArray("history");
        //平
        int even_count = history.getJSONObject(0).getIntValue("even_count");
        //胜
        int win_count = history.getJSONObject(0).getIntValue("win_count");
        //输
        int lost_count = history.getJSONObject(0).getIntValue("lost_count");
        int history_count = history.getJSONObject(0).getIntValue("history_count");
        String hs = String.format(getResources().getString(R.string.zq_history),
                history_count, codes[3], win_count, even_count, lost_count);
        tvHistoryOne.setText(Html.fromHtml(hs));
        //左边队伍战绩
        JSONArray home_recent = o.getJSONArray("home_recent");
        //平
        int home_even_count = home_recent.getJSONObject(0).getIntValue("even_count");
        //胜
        int home_win_count = home_recent.getJSONObject(0).getIntValue("win_count");
        //输
        int home_lost_count = home_recent.getJSONObject(0).getIntValue("lost_count");
        String hr = getResources().getString(R.string.zq_recent);
        tvRecentOne.setText(String.format(hr, home_win_count, home_even_count, home_lost_count));

        //右边队伍战绩
        JSONArray guest_recent = o.getJSONArray("guest_recent");
        //平
        int guest_even_count = guest_recent.getJSONObject(0).getIntValue("even_count");
        //胜
        int guest_win_count = guest_recent.getJSONObject(0).getIntValue("win_count");
        //输
        int guest_lost_count = guest_recent.getJSONObject(0).getIntValue("lost_count");
        String gr = getResources().getString(R.string.zq_recent);
        tvRecentTwo.setText(String.format(gr, guest_win_count, guest_even_count, guest_lost_count));

        //左边队伍排名
        String home_team_rank = o.getString("home_team_rank");
        tvRankOne.setText(home_team_rank);
        //右边队伍排名
        String guest_team_rank = o.getString("guest_team_rank");
        tvRankTwo.setText(guest_team_rank);
        //投注比例
        JSONArray match_ratio = o.getJSONArray("match_ratio");
        String play_id = match_ratio.getJSONObject(0).getString("PLAY_ID");
        //平
        String enen_ratio = match_ratio.getJSONObject(0).getString("ENEN_RATIO");
        tvRatioTwo.setText(enen_ratio + "%");
        //输
        String lost_ratio = match_ratio.getJSONObject(0).getString("LOST_RATIO");
        tvRatioThree.setText(lost_ratio + "%");
        //胜
        String win_ratio = match_ratio.getJSONObject(0).getString("WIN_RATIO");
        tvRatioOne.setText(win_ratio + "%");
        //这里我们要根据实际的情况，我判断是否可以查看赛事分析
        String goto_detail = o.getString("goto_detail");
        if ("0".equals(goto_detail)) {
            final String goto_url = o.getString("goto_url");
            //这里表示可以查看赛事详情；
            tvXx.setVisibility(View.VISIBLE);
            tvXx.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    //这里执行的操作跳转到web页面；

                    ;
                    tvXx.getContext().startActivity(NewWebViewHelperActivity.getIntent(tvXx.getContext(), goto_url, "赛事详情"));
                }
            });
        } else {
            tvXx.setVisibility(View.GONE);
        }
    }

    //混投点击更多玩法
    @OnClick(R.id.cb_more)
    void more(View v) {
        execCheckParam((CheckBox) v, "更多玩法");
    }

    //其他投注
    @OnClick(R.id.cb_touzhu)
    void cbTouzhu(View v) {
        execCheckParam((CheckBox) v, "立即投注");
    }

    //重置投注按钮状态(CheckBox)
    void resetCheckBoxStatus(final CheckBox cb, final String buttonText) {
        //设置默认选中
        String desc = mItem.getMap() != null && mItem.getMapLength() > 0 ? "已选中" + mItem.getMapLength() + "项" : buttonText;
        cb.setText(desc);
        cb.setChecked(!buttonText.equals(desc));
    }

    /**
     * 处理选中的数据与ui交互
     *
     * @param cb
     * @param buttonText
     */
    void execCheckParam(final CheckBox cb, final String buttonText) {
        resetCheckBoxStatus(cb, buttonText);
        JczqHHDialog.JCZQSHOWTYPE type;
        if (pager == 3) {
            type = JczqHHDialog.JCZQSHOWTYPE.SHOWBQC;
        } else if (pager == 4) {
            type = JczqHHDialog.JCZQSHOWTYPE.SHOWBF;
        } else if (pager == 6) {
            type = JczqHHDialog.JCZQSHOWTYPE.SHOWDG;
        } else {
            type = JczqHHDialog.JCZQSHOWTYPE.SHOWALL;
        }
        JczqHHDialog dialog = new JczqHHDialog(getContext(), this.mItem.getCodes(), this.mItem.getMap(), type);
        dialog.setListener(new OnSclestListener() {
            @Override
            public void sure(Map<String, Map<String, String>> map) {
                if (mItem.getMap() != null)
                    mItem.getMap().clear();
                mItem.setMap(map);
                String desc = mItem.getMapLength() > 0 ? "已选中" + mItem.getMapLength() + "项" : buttonText;
                cb.setText(desc);
                cb.setChecked(!buttonText.equals(desc));
                init();
                statistics();
            }
        });
        dialog.show();
    }

    void initSPF(List<String[]> strList) {
        boolean isDanGuan = false;
        //当前采种下面有几种比例选项 llspf 第一个是textview
        String[] strings = strList.get(0);
        for (int i = 0; i < strings.length; i++) {
            //CheckBox cb = (CheckBox)llspf.getChildAt(i+1);
            CheckBox cb = (CheckBox) llSpfOdds.getChildAt(i);
            cb.setOnClickListener(this);
            StringBuilder tag = new StringBuilder("0_spf_" + i + "_" + strings[i]);

            cb.setClickable(false);
            cb.setText("未开售");

            if (i == 1) {
                if (!TextUtils.isEmpty(strings[i]) && Double.parseDouble(strings[i]) != 0) {

                    cb.setClickable(true);
                    cb.setEnabled(true);
                    cb.setText(("平" + strings[i]));
                    tag.append("_平");
                }

            } else if (i == 0) {

                if (!TextUtils.isEmpty(strings[i]) && Double.parseDouble(strings[i]) != 0) {
                    cb.setClickable(true);
                    cb.setEnabled(true);
                    isDanGuan = addBlue(cb, "spf");
                    cb.setText(("胜" + strings[i]));
                    tag.append("_胜");
                }


            } else if (i == 2) {

                if (!TextUtils.isEmpty(strings[i]) && Double.parseDouble(strings[i]) != 0) {
                    cb.setClickable(true);
                    cb.setEnabled(true);
                    cb.setText(("负" + strings[i]));
                    tag.append("_负");
                }

            }
            tag.append("_" + spf[i]);
            cb.setTag(tag.toString());

            if (pager == 6) {
                saleTime(cb, isNotSale(strings[i])|| !isDanGuan, "spf");
            } else {
                saleTime(cb, isNotSale(strings[i]), "spf");
            }
            cb.setChecked(isCheckThisView(cb.getTag().toString(), "0"));
        }
    }

    //支持单关的小蓝点
    @TargetApi(Build.VERSION_CODES.M)
    boolean addBlue(TextView view, String realtype) {
        int mid = -1;
        boolean itemDgBool;
        switch (realtype) {
            case "bqc":
                mid = 0;
                break;
            case "cbf":
                mid = 1;
                break;
            case "jqs":
                mid = 2;
                break;
            case "rqspf":
                mid = 3;
                break;
            case "spf":
                mid = 4;
                break;
        }
        int value = TextUtils.isEmpty(codes[19]) ? 0 : Integer.parseInt(codes[19]);
        itemDgBool = ((value & 1 << mid) == (1 << mid));    //这是什么意思？
        view.setCompoundDrawables(null, null, null, null);
        if (itemDgBool) {
            int cH = ScreenUtil.dip2px(view.getContext(), 20);
            view.setCompoundDrawables(null, null, null, null);
            Drawable myImage = ContextCompat.getDrawable(getContext(), R.mipmap.img_danguan);
            myImage.setBounds(0, -10, cH, cH);
            view.setCompoundDrawables(myImage, null, null, null);
        }
        return itemDgBool;
    }

    void initRQSPF(List<String[]> strList, String value) {
        //当前采种下面有几种比例选项 llrqspf 第一个是textview
        boolean isDanGuan = false;
        String[] strings = strList.get(1);
        for (int i = 0; i < strings.length; i++) {
            //CheckBox cb = (CheckBox)llrqspf.getChildAt(i+1);
            CheckBox cb = (CheckBox) llRspfOdds.getChildAt(i);
            StringBuilder tag = new StringBuilder("1_rqspf_" + i + "_" + strings[i]);
            cb.setOnClickListener(this);
            if (i == 0) {
                 isDanGuan = addBlue(cb, "rqspf");
//                String color = Integer.parseInt(value) > 0 ? "#f03d3d":"#14a514";
                cb.setText(("胜" + strings[i]));
//                cb.setText(Html.fromHtml(String.format(getResources().getString(R.string.jczq_fl),"胜",color,value,strings[i])));
                tv_rqspf_txt.setText(value);
                //tv_rqspf_txt.setBackgroundColor(BitmapUtil.getTextColor(codes[17]));//codes[17]
                tag.append("_胜");
            } else if (i == 1) {
                cb.setText(("平" + strings[i]));
                tag.append("_平");
            } else if (i == 2) {
                cb.setText(("负" + strings[i]));
                tag.append("_负");
            }
            tag.append("_" + spf[i]);
            cb.setTag(tag.toString());
            cb.setEnabled(true);
            cb.setTextColor(ContextCompat.getColorStateList(getContext(), R.color.black_white_selector));

            if (pager == 6){
                saleTime(cb, isNotSale(strings[i])|| !isDanGuan, "rspf");
            }else{
                saleTime(cb, isNotSale(strings[i])|| pager == 6, "rspf");
            }

            cb.setChecked(isCheckThisView(cb.getTag().toString(), "1"));
        }
    }

    void initBQC() {
        addBlue(cbTouzhu, "bqc");
    }

    void initBF() {
        addBlue(cbTouzhu, "cbf");
    }

    void initZJQ(List<String[]> strList) {
        //当前采种下面有几种比例选项
        String[] str0 = strList.get(2);
        int childCount = llAll.getChildCount();//混投布局是上下两个linearlayout 每个 linearlayout下四个子view
        int index = 0;
        for (int i = 0; i < childCount; i++) {
            ViewGroup child = (ViewGroup) llAll.getChildAt(i);
            for (int j = 0; j < child.getChildCount(); j++) {
                CheckBox cb = (CheckBox) child.getChildAt(j);
                if (i == 0 && j == 0)
                    addBlue(cb, "jqs");
                StringBuilder tag = new StringBuilder("2_jqs_" + index + "_" + str0[index] + "_" + index + "_" + index);
                cb.setOnClickListener(this);
                StringBuilder sb = new StringBuilder();
                sb.append(index);
                if (i == childCount - 1 && j == child.getChildCount() - 1)
                    sb.append("球+");
                else
                    sb.append("球");
                sb.append("<br/><small><small>");
                sb.append(str0[index]);
                sb.append("</small></small>");
                cb.setText(Html.fromHtml(sb.toString()));
                cb.setTag(tag.toString());
                cb.setChecked(isCheckThisView(cb.getTag().toString(), "2"));

                saleTime(cb, isNotSale(str0[index]));
                index++;
            }
        }
    }

    /**
     * 判断是否开售的一个逻辑
     * @param valueStr
     * @return
     */
    public boolean isNotSale(String valueStr){
        float isEmpty=-1;
        try {
            isEmpty = Float.parseFloat(valueStr);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        if((isEmpty!=-1 && isEmpty == 0) || TextUtils.isEmpty(valueStr)){
            return true;
        }
        return false;
    }

    //一个默认的实现；
    void saleTime(CheckBox cb, boolean isNotSale) {
        saleTime(cb, isNotSale, "");
    }

    /**
     * 设置开售时间
     *
     * @param cb        具体的某个checkBox
     * @param isNotSale 是否开售了
     * @param playMode  具体是哪种玩法,spf,rspf,zjq
     */
    void saleTime(CheckBox cb, boolean isNotSale, String playMode) {
        cb.setEnabled(true);

        //由于page不同页面不同，所以我们分开讨论；
        if (pager == 6) {
            //这里是单关，我们要显示未开售，单关固赔

            //这里在开售的那个三个checkBox贴了一个TextView，
            // 如果没有开售就显示textView:,这里仅支持，胜负彩和让胜平负
            View outView = null;
            View innerTextView = null;
            if (playMode.equals("spf")) {
                outView = llSpfOdds;
                innerTextView = tvSpfOdds;
            } else if (playMode.equals("rspf")) {
                outView = llRspfOdds;
                innerTextView = tvRspfOdds;
            }
            if (outView != null && innerTextView != null) {
                outView.setVisibility(View.VISIBLE);
                innerTextView.setVisibility(View.INVISIBLE);
            }
            if (isNotSale) {
                if (outView != null && innerTextView != null) {
                    outView.setVisibility(View.INVISIBLE);
                    innerTextView.setVisibility(View.VISIBLE);
                }
                if (outView != null) {
                    outView.setVisibility(View.INVISIBLE);
                    innerTextView.setVisibility(View.VISIBLE);
                }
            }

        } else {

            if (playMode.equals("spf")) {
                llSpfOdds.setVisibility(View.INVISIBLE);
                tvSpfOdds.setVisibility(View.INVISIBLE);
            } else if (playMode.equals("rspf")) {
                llRspfOdds.setVisibility(View.INVISIBLE);
                tvRspfOdds.setVisibility(View.INVISIBLE);
            }

            //这里普通的情况；
            //这里在开售的那个三个checkBox贴了一个TextView，
            // 如果没有开售就显示textView:,这里仅支持，胜负彩和让胜平负
            View outView = null;
            tvRspfOdds.setVisibility(View.INVISIBLE);
            if (playMode.equals("spf")) {
                outView = llSpfOdds;
            } else if (playMode.equals("rspf")) {
                outView = llRspfOdds;
            }
            if (outView != null) {
                outView.setVisibility(View.VISIBLE);
            }
            if (isNotSale) {
                cb.setText("未开售");
                cb.setEnabled(false);

                if (outView != null) {
                    outView.setVisibility(View.VISIBLE);
                }
            }

        }
    }

    @Override
    public void onClick(View v) {
        if (mItem.getMap() == null) {
            cMap = new HashMap<>();
            mItem.setMap(cMap);
        } else {
            cMap = mItem.getMap();
        }
        String tag = v.getTag().toString();
        String key = tag.substring(0, 1);
        String value = tag;
        if (cMap.get(key) != null) {
            //有则删除 无则添加 - 等同于没选中则选中 选中了则取消
            if (cMap.get(key).get(value) != null) {
                cMap.get(key).remove(value);
            } else {
                cMap.get(key).put(value, value);
            }
        } else {
            Map<String, String> map = new HashMap<>();
            map.put(value, value);
            cMap.put(key, map);
        }
        if (cMap.get(key) != null && cMap.get(key).values().size() <= 0)
            cMap.remove(key);
        String desc = mItem.getMapLength() > 0 ? "已选中" + mItem.getMapLength() + "项" : "更多玩法";
        cb_more.setText(desc);
        cb_more.setChecked(!"更多玩法".equals(desc));
        statistics();
    }

    /**
     * 解析tag参数
     *
     * @param tag
     * @return
     */

    boolean isCheckThisView(String tag, String index) {
        if (this.mItem.getMap() == null) return false;
        if (this.mItem.getMap().get(index) != null) {
            return this.mItem.getMap().get(index).get(tag) != null;
        }
        return false;
    }

    //统计勾选的数据
    private void statistics() {
        if (mItem.getMapLength() > 0) {
            if (!Utils.ZQ_ITEM_LIST.contains(mItem)) {
                if (mPosition < Utils.ZQ_ITEM_LIST.size())
                    Utils.ZQ_ITEM_LIST.add(mPosition, mItem);
                else
                    Utils.ZQ_ITEM_LIST.add(mItem);
            }
        } else {
            if (Utils.ZQ_ITEM_LIST.contains(mItem)) {
                Utils.ZQ_ITEM_LIST.remove(mItem);
            }
        }
        if (changed != null)
            changed.onClickSetChangedText();
    }

    public void setChangeListener(Callback change) {
        this.changed = change;
    }
}
